package org.dromara.system.service.impl;

import org.dromara.system.service.GenTableColumnService;
import org.dromara.system.pojo.entity.GenTableColumnDO;
import org.dromara.system.pojo.bo.GenTableColumnBO;
import org.dromara.system.pojo.qo.GenTableColumnQO;
import org.dromara.system.pojo.vo.GenTableColumnVO;
import org.dromara.system.mapper.GenTableColumnMapper;
import org.springframework.stereotype.Service;

import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.utils.BeanCopyUtils;

import java.util.List;

/**
 * 代码生成业务表字段 服务层实现。
 *
  * @author mkj
  * @since 2024-07-21
 */
@RequiredArgsConstructor
@Service
public class GenTableColumnServiceImpl  implements GenTableColumnService {

    private final GenTableColumnMapper genTableColumnMapper;

    @Override
    public boolean add(GenTableColumnBO genTableColumnBO) {
        GenTableColumnDO genTableColumnDO = BeanCopyUtils.copy(genTableColumnBO, GenTableColumnDO.class);
        return genTableColumnMapper.insert(genTableColumnDO) > 0;
    }

    @Override
    public boolean remove(Long id) {
        return genTableColumnMapper.deleteById(id) > 0;
    }

    @Override
    public boolean update(GenTableColumnBO genTableColumnBO) {
        GenTableColumnDO genTableColumnDO = BeanCopyUtils.copy(genTableColumnBO, GenTableColumnDO.class);
        return genTableColumnMapper.update(genTableColumnDO) > 0;
    }

    @Override
    public List<GenTableColumnVO> list(GenTableColumnQO genTableColumnQO) {
        GenTableColumnDO genTableColumnDO = BeanCopyUtils.copy(genTableColumnQO, GenTableColumnDO.class);
        QueryWrapper queryWrapper = QueryWrapper.create(genTableColumnDO);
        return genTableColumnMapper.selectListByQueryAs(queryWrapper, GenTableColumnVO.class);
    }

    @Override
    public GenTableColumnVO getInfo(@PathVariable Long id) {
        GenTableColumnDO genTableColumnDO = genTableColumnMapper.selectOneById(id);
        if (genTableColumnDO == null){
            return null;
        }
        return BeanCopyUtils.copy(genTableColumnDO, GenTableColumnVO.class);
    }

    @Override
    public Page<GenTableColumnVO> page(GenTableColumnQO page) {
        return genTableColumnMapper.paginateAs(page.getPageNumber(), page.getPageSize(), QueryWrapper.create(page), GenTableColumnVO.class);
    }

}

